package com.java.yz.day05.homework;

/*
    合并数组操作：有下面一个数组：{1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}

   将上面的数组的0去掉，不为0的存入一个新的数组中
   新的数组为： {1,3,4,5,6,6,5,4,7,6,7,5}


   做题前分析
 */

public class Text02 {
    public static void main(String[] args) {
        int[] array1 = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5};
        int count = 0;
        for (int i = 0; i < array1.length; i++) {
            if (0 != array1[i]) {
                count++;
            }

        }
        int[] array2 = new int[count];
        System.out.println(array2.length);
        int index=0;
        for (int i = 0; i < array1.length; i++) {
            if (0!=array1[i]){
                array2[index]=array1[i];
                index++;
            }
        }
        ArrayPrint(array2);
    }
    public static void ArrayPrint(int[] array){
        for (int i = 0; i < array.length; i++) {
            if(i==0){
                System.out.print("["+array[0]+",");
            }
            else if (i==array.length-1){
                System.out.println(array[array.length-1]+"]");
            }
            else {
                System.out.print(array[i]+",");
            }
        }
    }
}
